/*
 * Project: BoboDesignPattern
 * 
 * File Created at 2019年3月10日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package test.lesson3.sort;

import java.util.Arrays;

/**
 * @Type InsertSort
 * @Desc
 * @author 52489
 * @date 2019年3月10日
 * @Version V1.0
 */
public class InsertSort {

    public static int[] sort(int[] nums) {
        for (int i = 0; i < nums.length - 1; i++) {
            int stard = nums[i + 1];
            for (int j = 0; j < i + 1; j++) {
                if (nums[i - j] > stard) {
                    int tmp = nums[i - j + 1];
                    nums[i - j + 1] = nums[i - j];
                    nums[i - j] = tmp;
                } else {
                    break;
                }
            }
        }

        return nums;
    }

    public static void main(String[] args) {
        int nums[] = { 10, 1, 3, 5, 12, 9, 3, 7, 6, 13, 4 };
        System.out.println(Arrays.toString(InsertSort.sort(nums)));

    }

}
